package com.dykj.fireFighting.server.base.dev.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dykj.fireFighting.api.base.bigdata.device.entity.Device;
import com.dykj.fireFighting.api.base.bigdata.device.vo.DevHisVo;
import com.dykj.fireFighting.api.base.dev.entity.DevHis;
import com.dykj.fireFighting.api.base.dev.entity.vo.FaultVo;
import com.dykj.fireFighting.api.base.dev.entity.vo.FireVo;
import com.dykj.fireFighting.api.base.dev.service.IDevHisService;
import com.dykj.fireFighting.api.base.dev.vo.RateVo;
import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.server.base.dev.mapper.DevHisMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 火灾自动报警设备运行记录
 *
 * @Author LJJ
 * @Date 2021-06-30 14:45:09
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class DevHisServiceImpl extends BaseServiceImpl<DevHisMapper, DevHis> implements IDevHisService {

    @Override
    public int getFireNum(String id) {
        return this.baseMapper.getFireNum(id);
    }

    @Override
    public int getCurrentFireNum(String id) {
        return this.baseMapper.getCurrentFireNum(id);
    }

    @Override
    public int getUpFireNum(String s) {
        return this.baseMapper.getUpFireNum(s);
    }

    @Override
    public int getCenterFireNum(List<String> ids,String beginTime,String endTime) {
        return this.baseMapper.getCenterFireNum(ids,beginTime,endTime);
    }

    @Override
    public int getCenterCurrentFire(List<String> ids) {
        return this.baseMapper.getCenterCurrentFire(ids);
    }

    @Override
    public int getCenterUpFire(List<String> ids) {
        return this.baseMapper.getCenterUpFire(ids);
    }

    @Autowired
    private IEnterpriseService iEnterpriseService;

    @Override
    public List<DevHisVo> queryPoliceStatistical(String unitId) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(unitId)) {
            List<Enterprise> enterpriseList = iEnterpriseService.queryUnitSelect(unitId);
            if (CollectionUtil.isNotEmpty(enterpriseList)) {
                params.put("enterpriseList", enterpriseList);
            }
        }
        return this.baseMapper.queryPoliceStatistical(params);
    }

    @Override
    public List<DevHisVo> queryRateStatistical(String unitId) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(unitId)) {
            List<Enterprise> enterpriseList = iEnterpriseService.queryUnitSelect(unitId);
            if (CollectionUtil.isNotEmpty(enterpriseList)) {
                params.put("enterpriseList", enterpriseList);
            }
        }
        return this.baseMapper.queryRateStatistical(params);
    }

    @Override
    public int getFireByTime(String s, String beginTime, String endTime) {
        return this.baseMapper.getFireByTime(s,beginTime,endTime);
    }

    @Override
    public int getAlreadyReviewCount(HashMap<String, Object> params) {
        return this.baseMapper.getAlreadyReviewCount(params);
    }

    @Override
    public int getEffectCount(HashMap<String, Object> params) {
        return this.baseMapper.getEffectCount(params);
    }

    @Override
    public int getCenterFaultNum(List<String> ids, String beginTime, String endTime) {
        return this.baseMapper.getCenterFaultNum(ids, beginTime, endTime);
    }

    @Override
    public List<FireVo> getViewedFireList(List<String> ids, String beginTime, String endTime) {
        return this.baseMapper.getViewedFireList(ids,beginTime,endTime);
    }

    @Override
    public List<RateVo> getMonthRate(HashMap<String, Object> params) {
        return this.baseMapper.getMonthRate(params);
    }

    @Override
    public List<FaultVo> getFaultList(List<String> ids, String beginTime, String endTime) {
        return this.baseMapper.getFaultList(ids,beginTime,endTime);
    }

    @Override
    public int countFaultByTime(String id, String beginTime, String endTime,String tableName) {
        return this.baseMapper.countFaultByTime(id,beginTime,endTime,tableName);
    }

    @Override
    public int getUnitNum(String unitId, String beginDate, String endDate, String tableName) {
        return this.baseMapper.getUnitNum(unitId,beginDate,endDate, tableName);
    }

    @Override
    public List<FireVo> getNewList(String tableName,String s, Integer read) {
        return this.baseMapper.getNewList(tableName,s,read);
    }
}
